/*
 * Rhy Events Core Lib
 * 
 * @author Tristan Maindron
 * 
 */

Rhy.on = function(o, event, callback){
    if (o.attachEvent) {
        o.attachEvent("on"+event, callback);
    } 
    else{
        o.addEventListener(event, callback, false); 
    }
}

Rhy.off = function(o, event, callback){
    if (o.detachEvent) {
        o.detachEvent("on"+event, callback);
    } 
    else{
        o.removeEventListener(event, callback); 
    }
}

Rhy.event = {
   source: function(e){
       return e.srcElement != null ? e.srcElement : e.target;
   },
   
   kill: function(e){
        if(!e){ 
            e = window.event;
        }
        //e.cancelBubble is supported by IE - this will kill the bubbling process.
        e.cancelBubble = true;
        e.returnValue = false;

        //e.stopPropagation works only in Firefox.
        if (e.stopPropagation) {
            e.stopPropagation();
            e.preventDefault();
        }
   },
   
   addListener:    Rhy.on,
   removeListener: Rhy.off
};
